﻿using System.Collections.Generic;
using Best.SmartCms.Domain;
using Best.SmartCms.Dto.Response;
using Best.SmartCms.Dto;
using Best.SmartCms.Dto.Common;
using Best.SmartCms.Service;
using Microsoft.AspNetCore.Mvc;

namespace Best.SmartCms.API.Controllers
{
    /// <summary>
    /// Category
    /// </summary>
    public class CategoryController : Controller
    {
        private readonly CategoryService _categoryService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="categoryService"></param>
        public CategoryController(CategoryService categoryService)
        {
            _categoryService = categoryService;
        }


        /// <summary>
        /// 列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Route("category/pagelist")]
        public ApiResponse<List<CategoryListDto>> PageList()
        {
            var ret = _categoryService.PageList();
            return ApiResponse<List<CategoryListDto>>.Succeeds(ret);
        }


        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("category/create")]
        public ApiResponse Create([FromBody]CategoryEditDto dto)
        {
             _categoryService.Create(dto);
            return ApiResponse.Succeeds();
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("category/edit")]
        public ApiResponse Edit([FromBody]CategoryEditDto dto)
        {
            _categoryService.Edit(dto);
            return ApiResponse.Succeeds();
        }


        /// <summary>
        /// 详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("category/Info")]
        public ApiResponse<CategoryEditDto> Info(long id)
        {
            var ret = _categoryService.Info(id);
            return ApiResponse<CategoryEditDto>.Succeeds(ret);
        }


        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("category/delete")]
        public ApiResponse Delete(long id)
        {
            _categoryService.Delete(id);
            return ApiResponse.Succeeds();
        }

        /// <summary>
        /// 选择
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("category/Option")]
        public ApiResponse<List<SelectOptionDto>> Option(long? id)
        {
            var list = _categoryService.Option(id);
            return ApiResponse<List<SelectOptionDto>>.Succeeds(list);
        }
    }
}